package com.fatgirl.utils
{
	
	
	import flash.net.SharedObject;

	/**
	 *  
	 * 基于SharedObject的flash Cookie
	 * @author iceman
	 * 
	 */
	public class CookieManager
	{
		private static const OBJ_NAME:String = "FatGame";
		public function CookieManager()
		{
			
		}
		/**
		 * 获取共享对象数据 
		 * @param _key
		 * @return 
		 * 
		 */
		public static function getValue(_key:String):Object
		{
			try
			{
				var t_sharedObj:SharedObject = SharedObject.getLocal(OBJ_NAME,"/");
				return t_sharedObj.data[_key];

			}
			catch(e:*)
			{
				throwError(CookieManager,FatError.COOKIEMANGER_ERROR);
				return null;
			}
			return null;
		}
		/**
		 * 添加共享对象  
		 * 返回是否成功
		 * @param _key
		 * @param _value
		 * @return 
		 * 
		 */
		public static function put(_key:String,_value:Object):Boolean
		{
			try
			{
				var t_sharedObj:SharedObject = SharedObject.getLocal(OBJ_NAME,"/");
				t_sharedObj.data[_key] = _value;
				return true;
			}
			catch(e:*)
			{
				throwError(CookieManager,FatError.COOKIEMANGER_ERROR);
				return false;
			}
			return false;
		}
		/**
		 * 清理 共享对象 
		 * 
		 */
		public static function clear():void
		{
			try
			{
				var t_sharedObj:SharedObject = SharedObject.getLocal(OBJ_NAME,"/");
				t_sharedObj.clear();
			}
			catch(e:*)
			{
				throwError(CookieManager,FatError.COOKIEMANGER_ERROR);
			}
		}
	}
}